package com.network.vo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;
import java.util.Map;

public class RoleVo
{
    private Long id;
    private String name;
    private String remark;
    private String createBy;
    private List<Map<String, Object>> menus;

    @Autowired
    private JdbcTemplate template;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public List<MenuVo> getMenus()
    {
        //根据角色ID获取 角色下的所有菜单信息
        String sql="SELECT A.id,A.`name`,A.create_by as createBy,A.parent_id as parentId,A.url,A.type,A.icon,A.create_time as createTime,"
                +" (SELECT C.`name` FROM menu_t AS C where C.id>1 and C.parent_id=A.id) as parentName"
                +" from menu_t as A LEFT JOIN role_manu_t as B on A.id=B.menu_id where B.role_id=?";

        List<MenuVo> list= template.query(sql,new Object[]{id},new BeanPropertyRowMapper<>(MenuVo.class));

        return  list;
    }
}
